import time

from selenium.webdriver.common.by import By
from webdriver_helper import get_webdriver

driver = get_webdriver('chrome')

driver.get('http://101.34.221.219:8010/')

# 让页面最大化的方法
driver.maximize_window()
# 实现自动化操作业务流程
driver.find_element(By.XPATH, '//*[@id="search-input"]').send_keys('手机')
driver.find_element(By.XPATH, '//*[@id="ai-topsearch"]').click()

# /html/body/div[4]/div/ul/li[1]/div/a/div/p
# /html/body/div[4]/div/ul/li[2]/div/a/div/p
# /html/body/div[4]/div/ul/li[3]/div/a/div/p
# 隐式等待
# driver.implicitly_wait(10)
# t1 = driver.find_element(By.XPATH, '/html/body/div[4]/div/ul/li[1]/div/a/div/p').text
# print(t1)
# 强制等待
time.sleep(1)
goods_list = driver.find_elements(By.XPATH, '/html/body/div[4]/div/ul/li/div/a/div/p')
print(goods_list)
for goods in goods_list:
    print(goods.text)
    assert "手机" in goods.text

# 强制等待
time.sleep(5)
# 关闭驱动，回收资源
driver.quit()

# 切换到子页面
# driver.switch_to.frame()

# 切换主页面
# driver.switch_to.default_content()
